package week2.validator_ex;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class AuthenticatorFactory {
    private static Properties prop = new Properties();
    static {
        try {
            prop.load(new FileInputStream("src/week02/auth.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static Authenticator createAuthenticator() {
        KeyValueKeeper keeper = createKeyValueKeeper();
        Encrypter encrypter = createEncrypter();
        return new Authenticator(keeper, encrypter);
    }



    private static KeyValueKeeper createKeyValueKeeper() {
        KeyValueKeeper kvk = null;
        try {
            kvk = (KeyValueKeeper) Class.forName(prop.getProperty("KeyValueKeeper")).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return kvk;

    }

    private static Encrypter createEncrypter() {
        Encrypter  en = null;
        try {
            en = ( Encrypter ) Class.forName(prop.getProperty("Encrypter")).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return en;

    }
}